#include "cardpanel.h"

#include<QPainter>
CardPanel::CardPanel(QWidget *parent) : QWidget(parent)
{
    m_isfront = true;
}

void CardPanel::setImage(QPixmap &front, QPixmap &back)
{
    m_front = front;
    m_back = back;
    setFixedSize(m_front.size()); // 设置当前窗口和扑克牌图片的大小一致

    update();  // 手动更新界面
}

void CardPanel::setFrontSide(bool flag)
{
    m_isfront = flag;
}

bool CardPanel::isFrontSide()
{
    return m_isfront;
}

void CardPanel::setSelected(bool flag)
{
    m_isSelect = flag;
}

bool CardPanel::isSelected()
{
    return m_isSelect;
}

void CardPanel::setCard(Card &card)
{
    m_card = card;
}

Card CardPanel::getCard()
{
    return m_card;
}

void CardPanel::setOwner(Player *player)
{
    m_owner = player;
}

Player *CardPanel::getOwner()
{
    return m_owner;
}

// 这个函数什么时候会被调用呢？
// 当setImage中，设置好后手动调用update函数，这样框架就会自动调用这个函数
void CardPanel::paintEvent(QPaintEvent *event)
{
    QPainter p(this);
    if(m_isfront)
    {
        // rect()获取当前窗口的信息 用于绘制和当前窗口一样大小
        p.drawPixmap(rect(), m_front);
    }
    else
    {
        p.drawPixmap(rect(), m_back);
    }
}

void CardPanel::mousePressEvent(QMouseEvent *event)
{

}


